package core.world;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import sun.security.provider.MD5;
import sun.security.provider.SHA;

public class Wall {
	
	private Point p1, p2, center;
	private Rectangle outerBounds;
	public double dx, dy;
	boolean visible = true;
	
	public Wall(Point p1, Point p2){
		this.p1 = p1;
		this.p2 = p2;
		outerBounds= new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p1.x - p2.x)+1, Math.abs(p1.y - p2.y)+1);
		center = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2);
		
		double wdx, wdy;
		double length = p1.distance(p2);
		wdx = (p1.x - p2.x)/length;
		wdy = (p1.y - p2.y)/length;
		dx=wdy;
		dy=-wdx;
		//System.out.println("dx: "+dx+"  dy: "+dy);
	}
	
	public boolean intersects(Rectangle r){
		return CollisionHandler.intersects(p1, p2, r);
	}
	public boolean intersects(Point p3, Point p4){
		return CollisionHandler.intersects(p1, p2, p3, p4);
	}
	public void paint(Point screenOffset, int zoomDivider, Graphics g){
		if(visible){
			g.setColor(Color.white);
			g.drawLine((p1.x-screenOffset.x)/zoomDivider, (p1.y-screenOffset.y)/zoomDivider, (p2.x-screenOffset.x)/zoomDivider, (p2.y-screenOffset.y)/zoomDivider);
			g.setColor(Color.red);
			g.drawLine((center.x-screenOffset.x)/zoomDivider, (center.y-screenOffset.y)/zoomDivider, (int)(center.x+dx*30000-screenOffset.x)/zoomDivider, (int)(center.y+dy*30000-screenOffset.y)/zoomDivider);
		}
	}
	public void setVisible(boolean isVisible){
		visible = isVisible;
	}
	public Rectangle getOuterBounds(){
		return outerBounds;
	}
}
